home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / filutil / bison110.zip / HAIRY.BSN < prev    next >
Text File  |  1990-07-01  |  7KB  |  336 lines

  1. /* BISON template */
  2.  
  3. extern int timeclock;
  4.  
  5.  
  6. int yyerror;        /*  Yyerror and yycost are set by guards.    */
  7. int yycost;        /*  If yyerror is set to a nonzero value by a    */
  8.             /*  guard, the reduction with which the guard    */
  9.             /*  is associated is not performed, and the    */
  10.             /*  error recovery mechanism is invoked.    */
  11.             /*  Yycost indicates the cost of performing    */
  12.             /*  the reduction given the attributes of the    */
  13.             /*  symbols.                    */
  14.  
  15.  
  16. /*  YYMAXDEPTH indicates the size of the parser's state and value    */
  17. /*  stacks.                                */
  18.  
  19. #ifndef    YYMAXDEPTH
  20. #define    YYMAXDEPTH    500
  21. #endif
  22.  
  23. /*  YYMAXRULES must be at least as large as the number of rules that    */
  24. /*  could be placed in the rule queue.  That number could be determined    */
  25. /*  from the grammar and the size of the stack, but, as yet, it is not.    */
  26.  
  27. #ifndef    YYMAXRULES
  28. #define    YYMAXRULES    100
  29. #endif
  30.  
  31. #ifndef    YYMAXBACKUP
  32. #define YYMAXBACKUP    100
  33. #endif
  34.  
  35.  
  36. short    yyss[YYMAXDEPTH];    /*  the state stack            */
  37. YYSTYPE    yyvs[YYMAXDEPTH];    /*  the semantic value stack        */
  38. YYLTYPE yyls[YYMAXDEPTH];    /*  the location stack            */
  39. short    yyrq[YYMAXRULES];    /*  the rule queue            */
  40. int    yychar;            /*  the lookahead symbol        */
  41.  
  42. YYSTYPE    yylval;            /*  the semantic value of the        */
  43.                 /*  lookahead symbol            */
  44.  
  45. YYSTYPE yytval;            /*  the semantic value for the state    */
  46.                 /*  at the top of the state stack.    */
  47.  
  48. YYSTYPE yyval;            /*  the variable used to return        */
  49.                 /*  semantic values from the action    */
  50.                 /*  routines                */
  51.  
  52. YYLTYPE yylloc;        /*  location data for the lookahead    */
  53.                 /*  symbol                */
  54.  
  55. YYLTYPE yytloc;        /*  location data for the state at the    */
  56.                 /*  top of the state stack        */
  57.  
  58.  
  59. int    yynunlexed;
  60. short    yyunchar[YYMAXBACKUP];
  61. YYSTYPE    yyunval[YYMAXBACKUP];
  62. YYLTYPE yyunloc[YYMAXBACKUP];
  63.  
  64. short *yygssp;            /*  a pointer to the top of the state    */
  65.                 /*  stack; only set during error    */
  66.                 /*  recovery.                */
  67.  
  68. YYSTYPE *yygvsp;        /*  a pointer to the top of the value    */
  69.                 /*  stack; only set during error    */
  70.                 /*  recovery.                */
  71.  
  72. YYLTYPE *yyglsp;        /*  a pointer to the top of the        */
  73.                 /*  location stack; only set during    */
  74.                 /*  error recovery.            */
  75.  
  76.  
  77. /*  Yyget is an interface between the parser and the lexical analyzer.    */
  78. /*  It is costly to provide such an interface, but it avoids requiring    */
  79. /*  the lexical analyzer to be able to back up the scan.        */
  80.  
  81. yyget()
  82. {
  83.   if (yynunlexed > 0)
  84.     {
  85.       yynunlexed--;
  86.       yychar = yyunchar[yynunlexed];
  87.       yylval = yyunval[yynunlexed];
  88.       yylloc = yyunloc[yynunlexed];
  89.     }
  90.   else if (yychar <= 0)
  91.     yychar = 0;
  92.   else
  93.     {
  94.       yychar = yylex();
  95.       if (yychar < 0)
  96.     yychar = 0;
  97.       else yychar = YYTRANSLATE(yychar);
  98.     }
  99. }
  100.  
  101.  
  102.  
  103. yyunlex(chr, val, loc)
  104. int chr;
  105. YYSTYPE val;
  106. YYLTYPE loc;
  107. {
  108.   yyunchar[yynunlexed] = chr;
  109.   yyunval[yynunlexed] = val;
  110.   yyunloc[yynunlexed] = loc;
  111.   yynunlexed++;
  112. }
  113.  
  114.  
  115.  
  116. yyrestore(first, last)
  117. register short *first;
  118. register short *last;
  119. {
  120.   register short *ssp;
  121.   register short *rp;
  122.   register int symbol;
  123.   register int state;
  124.   register int tvalsaved;
  125.  
  126.   ssp = yygssp;
  127.   yyunlex(yychar, yylval, yylloc);
  128.  
  129.   tvalsaved = 0;
  130.   while (first != last)
  131.     {
  132.       symbol = yystos[*ssp];
  133.       if (symbol < YYNTBASE)
  134.     {
  135.       yyunlex(symbol, yytval, yytloc);
  136.       tvalsaved = 1;
  137.       ssp--;
  138.     }
  139.  
  140.       ssp--;
  141.  
  142.       if (first == yyrq)
  143.     first = yyrq + YYMAXRULES;
  144.  
  145.       first--;
  146.  
  147.       for (rp = yyrhs + yyprhs[*first]; symbol = *rp; rp++)
  148.     {
  149.       if (symbol < YYNTBASE)
  150.         state = yytable[yypact[*ssp] + symbol];
  151.       else
  152.         {
  153.           state = yypgoto[symbol - YYNTBASE] + *ssp;
  154.  
  155.           if (state >= 0 && state <= YYLAST && yycheck[state] == *ssp)
  156.         state = yytable[state];
  157.           else
  158.         state = yydefgoto[symbol - YYNTBASE];
  159.         }
  160.  
  161.       *++ssp = state;
  162.     }
  163.     }
  164.  
  165.   if ( ! tvalsaved && ssp > yyss)
  166.     {
  167.       yyunlex(yystos[*ssp], yytval, yytloc);
  168.       ssp--;
  169.     }
  170.  
  171.   yygssp = ssp;
  172. }
  173.  
  174.  
  175.  
  176. int
  177. yyparse()
  178. {
  179.   register int yystate;
  180.   register int yyn;
  181.   register short *yyssp;
  182.   register short *yyrq0;
  183.   register short *yyptr;
  184.   register YYSTYPE *yyvsp;
  185.  
  186.   int yylen;
  187.   YYLTYPE *yylsp;
  188.   short *yyrq1;
  189.   short *yyrq2;
  190.  
  191.   yystate = 0;
  192.   yyssp = yyss - 1;
  193.   yyvsp = yyvs - 1;
  194.   yylsp = yyls - 1;
  195.   yyrq0 = yyrq;
  196.   yyrq1 = yyrq0;
  197.   yyrq2 = yyrq0;
  198.  
  199.   yychar = yylex();
  200.   if (yychar < 0)
  201.     yychar = 0;
  202.   else yychar = YYTRANSLATE(yychar);
  203.  
  204. yynewstate:
  205.  
  206.   if (yyssp >= yyss + YYMAXDEPTH - 1)
  207.     {
  208.       yyabort("Parser Stack Overflow");
  209.       YYABORT;
  210.     }
  211.  
  212.   *++yyssp = yystate;
  213.  
  214. yyresume:
  215.  
  216.   yyn = yypact[yystate];
  217.   if (yyn == YYFLAG)
  218.     goto yydefault;
  219.  
  220.   yyn += yychar;
  221.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar)
  222.     goto yydefault;
  223.  
  224.   yyn = yytable[yyn];
  225.   if (yyn < 0)
  226.     {
  227.       yyn = -yyn;
  228.       goto yyreduce;
  229.     }
  230.   else if (yyn == 0)
  231.     goto yyerrlab;
  232.  
  233.   yystate = yyn;
  234.  
  235.   yyptr = yyrq2;
  236.   while (yyptr != yyrq1)
  237.     {
  238.       yyn = *yyptr++;
  239.       yylen = yyr2[yyn];
  240.       yyvsp -= yylen;
  241.       yylsp -= yylen;
  242.  
  243.       yyguard(yyn, yyvsp, yylsp);
  244.       if (yyerror)
  245.     goto yysemerr;
  246.  
  247.       yyaction(yyn, yyvsp, yylsp);
  248.       *++yyvsp = yyval;
  249.  
  250.       yylsp++;
  251.       if (yylen == 0)
  252.     {
  253.       yylsp->timestamp = timeclock;
  254.       yylsp->first_line = yytloc.first_line;
  255.       yylsp->first_column = yytloc.first_column;
  256.       yylsp->last_line = (yylsp-1)->last_line;
  257.       yylsp->last_column = (yylsp-1)->last_column;
  258.       yylsp->text = 0;
  259.     }
  260.       else
  261.     {
  262.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  263.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  264.     }
  265.  
  266.       if (yyptr == yyrq + YYMAXRULES)
  267.         yyptr = yyrq;
  268.     }
  269.  
  270.   if (yystate == YYFINAL)
  271.     YYACCEPT;
  272.  
  273.   yyrq2 = yyptr;
  274.   yyrq1 = yyrq0;
  275.  
  276.   *++yyvsp = yytval;
  277.   *++yylsp = yytloc;
  278.   yytval = yylval;
  279.   yytloc = yylloc;
  280.   yyget();
  281.  
  282.   goto yynewstate;
  283.  
  284. yydefault:
  285.  
  286.   yyn = yydefact[yystate];
  287.   if (yyn == 0)
  288.     goto yyerrlab;
  289.  
  290. yyreduce:
  291.  
  292.   *yyrq0++ = yyn;
  293.  
  294.   if (yyrq0 == yyrq + YYMAXRULES)
  295.     yyrq0 = yyrq;
  296.  
  297.   if (yyrq0 == yyrq2)
  298.     {
  299.       yyabort("Parser Rule Queue Overflow");
  300.       YYABORT;
  301.     }
  302.  
  303.   yyssp -= yyr2[yyn];
  304.   yyn = yyr1[yyn];
  305.  
  306.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  307.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  308.     yystate = yytable[yystate];
  309.   else
  310.     yystate = yydefgoto[yyn - YYNTBASE];
  311.  
  312.   goto yynewstate;
  313.  
  314. yysemerr:
  315.   *--yyptr = yyn;
  316.   yyrq2 = yyptr;
  317.   yyvsp += yyr2[yyn];
  318.  
  319. yyerrlab:
  320.  
  321.   yygssp = yyssp;
  322.   yygvsp = yyvsp;
  323.   yyglsp = yylsp;
  324.   yyrestore(yyrq0, yyrq2);
  325.   yyrecover();
  326.   yystate = *yygssp;
  327.   yyssp = yygssp;
  328.   yyvsp = yygvsp;
  329.   yyrq0 = yyrq;
  330.   yyrq1 = yyrq0;
  331.   yyrq2 = yyrq0;
  332.   goto yyresume;
  333. }
  334.  
  335. $
  336.